Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the Albums class.
	''' </summary>
	<Serializable> _
	Public Partial Class AlbumsCollection 
	Inherits ActiveList(Of Albums, AlbumsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the Albums table.
	''' </summary>
	<Serializable> _
	Public Partial Class Albums 
	Inherits ActiveRecord(Of Albums)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("Albums", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarAlbumid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarAlbumid.ColumnName = "albumid"
                colvarAlbumid.DataType = DbType.Int32
                colvarAlbumid.MaxLength = 0
                colvarAlbumid.AutoIncrement = true
                colvarAlbumid.IsNullable = false
                colvarAlbumid.IsPrimaryKey = true
                colvarAlbumid.IsForeignKey = false
                colvarAlbumid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarAlbumid)
                
                Dim colvarTitle As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTitle.ColumnName = "title"
                colvarTitle.DataType = DbType.String
                colvarTitle.MaxLength = 50
                colvarTitle.AutoIncrement = false
                colvarTitle.IsNullable = false
                colvarTitle.IsPrimaryKey = false
                colvarTitle.IsForeignKey = false
                colvarTitle.IsReadOnly = false
                
                
                schema.Columns.Add(colvarTitle)
                
                Dim colvarParentid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarParentid.ColumnName = "parentid"
                colvarParentid.DataType = DbType.Int32
                colvarParentid.MaxLength = 0
                colvarParentid.AutoIncrement = false
                colvarParentid.IsNullable = false
                colvarParentid.IsPrimaryKey = false
                colvarParentid.IsForeignKey = false
                colvarParentid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarParentid)
                
                Dim colvarIsprivate As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarIsprivate.ColumnName = "isprivate"
                colvarIsprivate.DataType = DbType.Boolean
                colvarIsprivate.MaxLength = 0
                colvarIsprivate.AutoIncrement = false
                colvarIsprivate.IsNullable = true
                colvarIsprivate.IsPrimaryKey = false
                colvarIsprivate.IsForeignKey = false
                colvarIsprivate.IsReadOnly = false
                
                
                schema.Columns.Add(colvarIsprivate)
                
                Dim colvarDescription As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarDescription.ColumnName = "description"
                colvarDescription.DataType = DbType.String
                colvarDescription.MaxLength = 500
                colvarDescription.AutoIncrement = false
                colvarDescription.IsNullable = true
                colvarDescription.IsPrimaryKey = false
                colvarDescription.IsForeignKey = false
                colvarDescription.IsReadOnly = false
                
                
                schema.Columns.Add(colvarDescription)
                
                Dim colvarOwnerid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarOwnerid.ColumnName = "ownerid"
                colvarOwnerid.DataType = DbType.Guid
                colvarOwnerid.MaxLength = 0
                colvarOwnerid.AutoIncrement = false
                colvarOwnerid.IsNullable = false
                colvarOwnerid.IsPrimaryKey = false
                colvarOwnerid.IsForeignKey = false
                colvarOwnerid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarOwnerid)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("Albums",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Albumid")> _
        Public Property Albumid As Integer 
			Get
				Return GetColumnValue(Of Integer)("albumid")
			End Get
		    
			Set
				SetColumnValue("albumid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Title")> _
        Public Property Title As String 
			Get
				Return GetColumnValue(Of String)("title")
			End Get
		    
			Set
				SetColumnValue("title", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Parentid")> _
        Public Property Parentid As Integer 
			Get
				Return GetColumnValue(Of Integer)("parentid")
			End Get
		    
			Set
				SetColumnValue("parentid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Isprivate")> _
        Public Property Isprivate As Nullable(Of Boolean) 
			Get
				Return GetColumnValue(Of Nullable(Of Boolean))("isprivate")
			End Get
		    
			Set
				SetColumnValue("isprivate", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Description")> _
        Public Property Description As String 
			Get
				Return GetColumnValue(Of String)("description")
			End Get
		    
			Set
				SetColumnValue("description", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Ownerid")> _
        Public Property Ownerid As Guid 
			Get
				Return GetColumnValue(Of Guid)("ownerid")
			End Get
		    
			Set
				SetColumnValue("ownerid", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    'no foreign key tables defined (0)
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varTitle As String,ByVal varParentid As Integer,ByVal varIsprivate As Nullable(Of Boolean),ByVal varDescription As String,ByVal varOwnerid As Guid)
			Dim item As Albums = New Albums()
			
            item.Title = varTitle
            
            item.Parentid = varParentid
            
            item.Isprivate = varIsprivate
            
            item.Description = varDescription
            
            item.Ownerid = varOwnerid
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varAlbumid As Integer,ByVal varTitle As String,ByVal varParentid As Integer,ByVal varIsprivate As Nullable(Of Boolean),ByVal varDescription As String,ByVal varOwnerid As Guid)
			Dim item As Albums = New Albums()
		    
                item.Albumid = varAlbumid
				
                item.Title = varTitle
				
                item.Parentid = varParentid
				
                item.Isprivate = varIsprivate
				
                item.Description = varDescription
				
                item.Ownerid = varOwnerid
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Albumid As String = "albumid"
            
            Public Shared Title As String = "title"
            
            Public Shared Parentid As String = "parentid"
            
            Public Shared Isprivate As String = "isprivate"
            
            Public Shared Description As String = "description"
            
            Public Shared Ownerid As String = "ownerid"
            
		End Structure
		#End Region
	End Class
End Namespace
